(bug 5908) Allow overriding the default category sort key for all items on a page...
authorRob Church <robchurch@users.mediawiki.org>
Fri, 29 Dec 2006 10:39:35 +0000 (10:39 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Fri, 29 Dec 2006 10:39:35 +0000 (10:39 +0000)
RELEASE-NOTES
includes/CoreParserFunctions.php
includes/MagicWord.php
includes/Parser.php
languages/messages/MessagesEn.php

index 3aa4894..4afa164 100644 (file)
@@ -423,7 +423,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 8401) Fix regression in SORBS lookup for some DNS setups
 * Use raw file descriptor in posix_isatty() check to avoid warning on
   Linux systems with at least some versions of PHP
-
+* (bug 5908) Allow overriding the default category sort key for all items on
+  a page using {{DEFAULTSORT}}
 
 == Languages updated ==
 
index 7974893..402a3ba 100644 (file)
@@ -180,6 +180,14 @@ class CoreParserFunctions {
                        return wfMsgForContent( 'nosuchspecialpage' );
                }
        }
+       
+       public static function defaultsort( $parser, $text ) {
+               $text = trim( $text );
+               if( strlen( $text ) > 0 )
+                       $parser->setDefaultSort( $text );
+               return '';
+       }
+       
 }
 
 ?>
index 0b6065d..60bfd0f 100644 (file)
@@ -101,6 +101,7 @@ class MagicWord {
                'contentlanguage',
                'pagesinnamespace',
                'numberofadmins',
+               'defaultsort',
        );
 
        static public $mObjects = array();
index 5ea0689..299c221 100644 (file)
@@ -100,7 +100,7 @@ class Parser
        var $mOutput, $mAutonumber, $mDTopen, $mStripState;
        var $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
        var $mInterwikiLinkHolders, $mLinkHolders, $mUniqPrefix;
-       var $mIncludeSizes;
+       var $mIncludeSizes, $mDefaultSort;
        var $mTemplates,        // cache of already loaded templates, avoids
                                // multiple SQL queries for the same string
            $mTemplatePath;     // stores an unsorted hash of all the templates already loaded
@@ -167,6 +167,7 @@ class Parser
                $this->setFunctionHook( 'padright', array( 'CoreParserFunctions', 'padright' ), SFH_NO_HASH );
                $this->setFunctionHook( 'anchorencode', array( 'CoreParserFunctions', 'anchorencode' ), SFH_NO_HASH );
                $this->setFunctionHook( 'special', array( 'CoreParserFunctions', 'special' ) );
+               $this->setFunctionHook( 'defaultsort', array( 'CoreParserFunctions', 'defaultsort' ), SFH_NO_HASH );
 
                if ( $wgAllowDisplayTitle ) {
                        $this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH );
@@ -231,6 +232,7 @@ class Parser
                        'post-expand' => 0,
                        'arg' => 0
                );
+               $this->mDefaultSort = false;
 
                wfRunHooks( 'ParserClearState', array( &$this ) );
                wfProfileOut( __METHOD__ );
@@ -1750,11 +1752,7 @@ class Parser
                                        $s = rtrim($s . "\n"); # bug 87
 
                                        if ( $wasblank ) {
-                                               if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
-                                                       $sortkey = $this->mTitle->getText();
-                                               } else {
-                                                       $sortkey = $this->mTitle->getPrefixedText();
-                                               }
+                                               $sortkey = $this->getDefaultSort();
                                        } else {
                                                $sortkey = $text;
                                        }
@@ -4667,6 +4665,32 @@ class Parser
                }
                return $this->mRevisionTimestamp;
        }
+       
+       /**
+        * Mutator for $mDefaultSort
+        *
+        * @param $sort New value
+        */
+       public function setDefaultSort( $sort ) {
+               $this->mDefaultSort = $sort;
+       }
+       
+       /**
+        * Accessor for $mDefaultSort
+        * Will use the title/prefixed title if none is set
+        *
+        * @return string
+        */
+       public function getDefaultSort() {
+               if( $this->mDefaultSort !== false ) {
+                       return $this->mDefaultSort;
+               } else {
+                       return $this->mTitle->getNamespace() == NS_CATEGORY
+                                       ? $this->mTitle->getText()
+                                       : $this->mTitle->getPrefixedText();
+               }
+       }
+       
 }
 
 /**
index 711b0e4..f597086 100644 (file)
@@ -332,6 +332,7 @@ $magicWords = array(
        'padleft'                => array( 0,    'PADLEFT'                ),
        'padright'               => array( 0,    'PADRIGHT'               ),
        'special'                => array( 0,    'special',               ),
+       'defaultsort'                    => array( 1,    'DEFAULTSORT:'                   ),
 );
 
 /**